// copyright (c) 2025 author:fio66<fio66@foxmail.com>. All rights reserved.
// date: 2025-08-22 17:18:29

#ifndef _AUDIO_PLAYER_SRC_MANAGER_AUDIO_PLAYER_MANAGER_H_
#define _AUDIO_PLAYER_SRC_MANAGER_AUDIO_PLAYER_MANAGER_H_

#include <map>
#include <vector>

#include "src/cef/audio_player_app.h"
#include "src/player/audio_player.h"
#include "src/manager/audio_file_manager.h"
#include "src/event/event_dispatcher.h"

namespace fio66 {
class AudioPlayerManager : public EventDispatcher {
 public:
  AudioPlayerManager() : app_(new AudioPlayerApp(this)), player_(new AudioPlayer(this)) {
    audio_file_manager_.DetectAudioFile("C:\\Users\\fio66\\Documents\\workspace\\js\\Quantify\\assets\\songs");
  }
  ~AudioPlayerManager() = default;

  CefRefPtr<AudioPlayerApp>& GetApp() { return app_; }
  CefRefPtr<AudioPlayer>& GetPlayer() { return player_; }
  const CefRefPtr<AudioPlayerApp>& GetApp() const { return app_; }
  const CefRefPtr<AudioPlayer>& GetPlayer() const { return player_; }

  void CallEvent(EventType event_type, const std::any& data) final;
  void RegisterEvent(EventType event_type, EventHandler* handler) final;
  void UnregisterEvent(EventType event_type, EventHandler* handler) final;

 private:
  CefRefPtr<AudioPlayerApp> app_;
  CefRefPtr<AudioPlayer> player_;

  AudioFileManager audio_file_manager_;
  std::map<EventType, std::vector<EventHandler*>> event_handlers_;
};
}  // namespace fio66

#endif  // _AUDIO_PLAYER_SRC_MANAGER_AUDIO_PLAYER_MANAGER_H_
